package com.gxa.modules.deviceManager.controller;

import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.deviceManager.entity.EquipmentClassification;
import com.gxa.modules.deviceManager.entity.EquipmentManagement;
import com.gxa.modules.deviceManager.form.EquipmentManagementForm;
import com.gxa.modules.deviceManager.service.EquipmentManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "设备管理")
@RestController
@Slf4j
public class EquipmentManagementController {
    @Autowired
    private EquipmentManagementService equipmentManagementService;

    @ApiOperation(value="设备管理查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "communityId",value ="查询必要条件-小区ID",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "equipmentClassify",value ="查询条件-设备分类名称",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "equipmentName",value ="查询条件-设备名称",dataType ="String"),
    }
    )
    @GetMapping("/equipmentManagement/list")
    public Result<PageUtils> list(@RequestParam Map<String,Object> params){
        log.info("----params-----{}----",params);
        PageUtils pageUtils = this.equipmentManagementService.queryByPage(params);
        return new Result<PageUtils>().ok(pageUtils);
    }

    @ApiOperation(value="设备管理添加接口")
    @PostMapping("/equipmentManagement/add")
    public Result add(@RequestBody EquipmentManagementForm equipmentManagementForm){
        log.info("----body-----{}----",equipmentManagementForm);
        EquipmentManagement equipmentManagement=new EquipmentManagement(equipmentManagementForm);
        this.equipmentManagementService.save(equipmentManagement);
        return new Result().ok();

    }

    @ApiOperation(value="设备管理删除接口")
    @DeleteMapping ("/equipmentManagement/delete")
    public Result delete(@RequestBody List<Integer> ids){
        log.info("----param-----{}----",ids);
        this.equipmentManagementService.removeByIds(ids);
        return new Result().ok();
    }

    @ApiOperation(value="设备管理修改接口")
    @PostMapping("/equipmentManagement/update")
    public Result update(@RequestBody EquipmentManagementForm equipmentManagementForm){
        log.info("----body-----{}----",equipmentManagementForm);
        EquipmentManagement equipmentManagement=new EquipmentManagement(equipmentManagementForm);
        this.equipmentManagementService.updateById(equipmentManagement);
        return new Result().ok();

    }

}
